package wh.ispct.util

import wh.ispct.LinkContent
import wh.ispct.Menu;

class MenuTagLib {
	static namespace = 'menu'
	def treemenu  = {
		out << "<div id='menu'>	<ul id='nav'>"
		
		LinkContent hostPage = LinkContent.findByLinkText("市局首页")
		out << "<li class='mainlevel' id='mainlevel_0' style='width:100px;'><a href='${hostPage.linkUrl}'>市局首页</a></li>"
		
		out << "<li class='mainlevel' id='mainlevel_0' style='width:100px;'><a href='/inspector/ '>支队首页</a></li>"
		ExtTreeData<Menu> treeData = Menu.getTreeData()
		List<ExtTreeNode> nodes = treeData.getRoots()
		nodes.each {
			if(it.visible){
				out << "<li class='mainlevel' id='mainlevel_${it.id}'><a href='/inspector/menu/show/${it.id}'>${it.text} </a>"
				if(it.children != null){
					out << "<ul id='sub_${it.id}'>"
					it.children.each {
						out << "<li  class='mainlevel' style='float:none;' id='mainlevel_${it.id}' ><a href='/inspector/menu/show/${it.id}'>${it.text} </a></li>"
					}
					out << "</ul>"
				}
				
				out << "</li>"
			}
		}
		out << "</ul></div>"
	}
	
	def selmenu  = {
		out << """ 
		<select name="menuId"  id="menuId">
		<option """ 
		if(!params.menuId) 
			out << " selected=true"
		out << """ value="">-选择类别-</option> """
		
		def menus = Menu.findAll("from Menu m where m.type=?",["content"])
		menus.each {
			out << "<option value='${it.id }'"
			
			if(it.id.toString().equals( params.menuId)){
					out << " selected=true "
			}
			out << ">${it.name }</option>"
			
		}
		out << "</select>"
	}
}
